﻿package src.game{
	import src.Heart;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.display.DisplayObjectContainer;
	
	public class LifeHolder extends Holder {
		private var numberOfLives:int;
		public function LifeHolder(display:DisplayObjectContainer) {
			super(display);
		}
		
		public function init(numberOfLives:int):void {
			this.numberOfLives = numberOfLives;
			for (var i:int = 0; i<numberOfLives; i++) {
				var heart:MovieClip = new Heart(); 
				heart.stop();
				heart.x = holder.width - heart.width / 2;
				heart.y = heart.height / 2 + i * (heart.height + heart.height / 4);
				holder.addChild(heart);
			}
		}
		
		public function lifeLost():void {
			if (holder.numChildren > 0)
				(MovieClip)(holder.getChildAt(holder.numChildren - 1)).play();
		}
		
		public function areLivesLeft():Boolean {
			return (holder.numChildren == 0) ? false : true;
		}
		
		public function restartLives():void {
			init(numberOfLives);
		}
	}
}